﻿using Domain.Repositorys;
using Domain.Entitys;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CMK = Domain.Entitys.CMK;
using Microsoft.EntityFrameworkCore;


namespace EFCore.Repositorys
{
    public class CMKRepositoy : ICMKRepositoy
    {
        private readonly MyDbContext myDbContext;

        public CMKRepositoy(MyDbContext myDbContext)
        {
            this.myDbContext = myDbContext;
        }

        public async Task<int> CMDeleteAsync(int id)
        {
            Domain.Entitys.CM cm = myDbContext.cMs.Find(id);
            myDbContext.cMs.Remove(cm);
            return await myDbContext.SaveChangesAsync();
        }

        public async Task<int> CMKAddAsync(CMK cMK)
        {
            await myDbContext.CMKs.AddAsync(cMK);
            return await myDbContext.SaveChangesAsync();
        }

        public async Task<int> CMKDeleteAsync(int id)
        {
            CMK cMK = myDbContext.CMKs.Find(id);
            myDbContext.CMKs.Remove(cMK);
            return await myDbContext.SaveChangesAsync();
        }

        public async Task<List<CMK>> CMKSelect(int pageIndex, int pageSize)
        {
            return await myDbContext.CMKs.Skip((pageIndex - 1) * pageSize ).Take(pageSize).ToListAsync();
        }

        public int CMKSelectCount()
        {
            return myDbContext.CMKs.Count();
        }

        public async Task<List<CMK>> CMKSelectMax()
        {
            return await myDbContext.CMKs.ToListAsync();
        }
    }
}
